// TOWN SCRIPT
//    Town 6: Lost City

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

short i,choice;
short lead_char;
short c;

body;

beginstate INIT_STATE;
// This state called whenever this town is entered

 c = 0;

 i = 0;
 while (i < 5) {
  if (char_ok(i)) {
   lead_char = i;
   i = 5;
  }
  else
   i = i + 1;
 }

if (get_sdf(100,0) > 0) {
 i = 6;
 set_incidental_sound(1);
 while (i < 120) {
  erase_char(i);
  i = i + 1;
 }
}
	
 set_crime_tolerance(1);

break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;

c = c + 1;

if (get_sdf(1,13) == 0) {
 if (c == 5)
  message_dialog("Must purify the world...","");
 if (c == 10)
  message_dialog("All weakness must be destroyed...","");
 if (c == 15)
  message_dialog("Find them, destroy them, cleanse yourself!","");
 if (c >= 20) {
  message_dialog("The voices keep repeating over and over without end. They are starting to get to you, starting to affect your mind. Where are these ideas radiating from?","");
  set_char_status(random_group_member(0),8,2,1,0);
  play_sound(46);
  set_flag(1,13,1);
  c = 0;
 }
}

if ((get_sdf(100,0) == 0) && (get_sdf(1,13) > 0) && (c >= 30) && (get_ran(1,1,10) <= 2)) {
 set_char_status(random_group_member(0),8,3,1,0);
 play_sound(46);
 c = 0; 
}
	
break;

beginstate 10;

reset_dialog();
add_dialog_str(0,"This passage leads down into a dark mine.",0);
add_dialog_choice(0,"Descend into the mine.");
add_dialog_choice(1,"Stay here.");
choice = run_dialog(1);
if (choice == 1)
 move_to_new_town(7,58,43);
if (choice == 2)
	block_entry(1);

break;


beginstate 11;

if (get_sdf(4,26) == 0) {
 set_flag(4,26,1);
 message_dialog("You open this box and find garbage, personal items of little value, and all sorts of random goods shoved inside. The only item of note is a nice silver bracelet.","You examine the object and see a glowing blue cross rune exactly like the one tatooed on Arivan's shoulder! You wonder what connection, if any, this bracelet may have to her.");
}

break;